package cn.afactory.tygz.ui.base.entity;

import org.json.JSONException;
import org.json.JSONObject;

/**
 * Created by Kenneth on 15/9/9.
 */
public class LoganThinkWordEntity {
    private static final long serialVersionUID = -8761930617021704749L;
    /**
     * 搜索DB 取值范围 sick, im, doctor, news, evaluation, medicine, famous_doctor
     */
    public String searchDB;

    /**
     * 内容
     */
    public String content;

    /**
     * 获取时间
     */
    public long getTime;

    /**
     * 反序列化函数，用于从json字符串反序列化本类型实例
     */
    public static LoganThinkWordEntity deserialize(String json) throws JSONException {
        if (json != null && !json.isEmpty()) {
            return deserialize(new JSONObject(json));
        }
        return null;
    }

    /**
     * 反序列化函数，用于从json节点对象反序列化本类型实例
     */
    public static LoganThinkWordEntity deserialize(JSONObject json) throws JSONException {
        if (json != null && json != JSONObject.NULL && json.length() > 0) {
            LoganThinkWordEntity result = new LoganThinkWordEntity();

            // 搜索DB 取值范围 sick, im, doctor, news, evaluation, medicine, famous_doctor

            if(!json.isNull("searchDB")){
                result.searchDB = json.optString("searchDB", null);
            }
            // 内容

            if(!json.isNull("content")){
                result.content = json.optString("content", null);
            }
            // 获取时间
            result.getTime = json.optLong("getTime");
            return result;
        }
        return null;
    }

    /*
     * 序列化函数，用于从对象生成数据字典
     */
    public JSONObject serialize() throws JSONException {
        JSONObject json = new JSONObject();

        // 搜索DB 取值范围 sick, im, doctor, news, evaluation, medicine, famous_doctor
        if(this.searchDB != null) { json.put("searchDB", this.searchDB); }

        // 内容
        if(this.content != null) { json.put("content", this.content); }

        // 获取时间
        json.put("getTime", this.getTime);

        return json;
    }
}
